import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import {createPinia} from 'pinia'
import router from './router'
import axios from 'axios'
import {createDiscreteApi} from "naive-ui";
import dayjs from 'dayjs'
const { message, notification, dialog } = createDiscreteApi(["message", "dialog", "notification"]);

axios.defaults.baseURL = 'http://localhost:3000'
// 请求拦截器
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  let token = localStorage.getItem('token')
  console.log('请求拦截器',token);
  if(token){
    config.headers['Authorization'] = "Bearer "+ token
  }
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

const app = createApp(App)

app.provide('axios',axios)
app.provide('message',message)
app.provide('notification',notification)
app.provide('dialog',dialog)
app.provide('baseUrl',axios.defaults.baseURL)
app.provide('dayjs',dayjs)

app.use(createPinia())
app.use(router)
app.mount('#app')
